#include <h5cpp/hdf5.hpp>
#include <iostream>

int main() {
  using namespace hdf5;

  // create a file
  file::File f = file::create("writing_vector.h5", file::AccessFlags::TRUNCATE);

  // create a group
  node::Group root_group = f.root();
  node::Group my_group = root_group.create_group("my_group");

  // create a dataset
  using data_type = std::vector<int>;
  data_type data{1, 2, 3, 4};
  node::Dataset dataset = my_group.create_dataset(
      "data", datatype::create<data_type>(), dataspace::create(data));

  // write to dataset
  dataset.write(data);

  node::Dataset dataset2 = my_group.create_dataset(
      "data2", datatype::create<data_type>(), dataspace::create(data));

  dataset2.write(data);

  std::for_each(node::RecursiveNodeIterator::begin(root_group),
                node::RecursiveNodeIterator::end(root_group),
                [](const node::Node &n) {
                  std::cout << "Node Type: " << n.type() << std::endl;
                  std::cout << "Node path: " << n.link().path() << std::endl;
                });

  std::for_each(node::NodeIterator::begin(my_group),
                node::NodeIterator::end(my_group), [](const node::Node &n) {
                  std::cout << "Node Type: " << n.type() << std::endl;
                  std::cout << "Node path: " << n.link().path() << std::endl;
                });

  return 0;
}